<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<base href="https://basedomain">
</head>
<body>
<script type="text/javascript">

function testCrossfade(css, queryProp)
{
    var div = document.createElement('div');
    div.setAttribute('style', css);
    document.body.appendChild(div);

    var result = getComputedStyle(div).getPropertyValue(queryProp);
    document.body.removeChild(div);
    return result;
}

test(() => {
  assert_equals(testCrossfade("opacity: 500%", "opacity"), '1');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://example.png), url(dummy://example.png), 50%)", "background-image"), '-webkit-cross-fade(url("dummy://example.png"), url("dummy://example.png"), 0.5)');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(-webkit-cross-fade(url(dummy://a.png), url(dummy://b.png), 25%), url(dummy://example.png), 50%)", "background-image"), '-webkit-cross-fade(-webkit-cross-fade(url("dummy://a.png"), url("dummy://b.png"), 0.25), url("dummy://example.png"), 0.5)');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://c.png), -webkit-cross-fade(url(dummy://a.png), url(dummy://b.png), 25%), 50%)", "background-image"), '-webkit-cross-fade(url("dummy://c.png"), -webkit-cross-fade(url("dummy://a.png"), url("dummy://b.png"), 0.25), 0.5)');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(linear-gradient(black, white), url(dummy://example.png), 10%)", "background-image"), '-webkit-cross-fade(linear-gradient(rgb(0, 0, 0), rgb(255, 255, 255)), url("dummy://example.png"), 0.1)');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://example.png), url(dummy://example.png), 1.0)", "background-image"), '-webkit-cross-fade(url("dummy://example.png"), url("dummy://example.png"), 1)');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://example.png), url(dummy://example.png), 0.5)", "background-image"), '-webkit-cross-fade(url("dummy://example.png"), url("dummy://example.png"), 0.5)');

  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://example.png), url(dummy://example.png), 5.0)", "background-image"), '-webkit-cross-fade(url("dummy://example.png"), url("dummy://example.png"), 1)');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://example.png), url(dummy://example.png), 700%)", "background-image"), '-webkit-cross-fade(url("dummy://example.png"), url("dummy://example.png"), 1)');

  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://example.png), url(dummy://example.png), -20)", "background-image"), '-webkit-cross-fade(url("dummy://example.png"), url("dummy://example.png"), 0)');
  assert_equals(testCrossfade("display:none;background-image: -webkit-cross-fade(url(example.png), url(example.png), 20%)", "background-image"), '-webkit-cross-fade(url("https://basedomain/example.png"), url("https://basedomain/example.png"), 0.2)');
}, 'Valid -webkit-cross-fade');

test(() => {
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://example.png), url(dummy://example.png))", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://example.png), url(dummy://example.png),)", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://example.png))", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(), url(dummy://example.png))", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(10px 20% 5px #bbb)", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(-webkit-cross-fade(-webkit-cross-fade()))", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(20%, url(dummy://a.png), url(dummy://b.png))", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(url(dummy://a.png),)", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(,)", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(,url(dummy://a.png))", "background-image"), 'none');
  assert_equals(testCrossfade("background-image: -webkit-cross-fade(,,,,,)", "background-image"), 'none');
}, 'Invalid -webkit-cross-fade');
</script>

</body>
</html>
